package com.jinlei.crm.commons.utils;

/**
 * 统一响应前端的数据格式
 */
public class Result {
    /**
     * 响应码
     */
    private Integer code;
    /**
     * 响应信息
     */
    private String message;
    /**
     * 响应数量
     */
    private Object data;

    public Result() {
    }

    public Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /*
        成功时调用
        新增、修改、删除
     */
    public static Result success(){
        return new Result(0,"success",null);
    }

    /*
       成功时调用
       查询
    */
    public static Result success(Object data){
        return new Result(0,"success",data);
    }

    /*
        失败时调用
     */
    public static Result error(){
        return new Result(-1,"error",null);
    }

    /*
        失败时调用
     */
    public static Result error(Integer code,String message){
        return new Result(code,message,null);
    }

    /*
        失败时调用
     */
    public static Result error(Object data){
        return new Result(-1,"error",data);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
